// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SQLFormat.java

package com.vandagroup.common.util;


public class SQLFormat
{

    public static String WHERE_OPERATOR_AND = " AND ";
    public static String WHERE_OPERATOR_OR = " OR ";

    public SQLFormat()
    {
    }

    public static String joinAsList(String params[], boolean isString)
    {
        String deli = isString ? "'" : "";
        String list = "";
        boolean head = true;
        for(int i = 0; params != null && i < params.length; i++)
            if(params[i] != null && params[i].length() != 0)
                if(!head)
                {
                    list = list + "," + deli + params[i] + deli;
                } else
                {
                    list = deli + params[i] + deli;
                    head = false;
                }

        return list;
    }

    public static String joinAsList(int params[])
    {
        String list = "";
        for(int i = 0; params != null && i < params.length; i++)
            if(i != 0)
                list = list + "," + params[i];
            else
                list = String.valueOf(params[i]);

        return list;
    }

    public static String truncate(String source, int maxLength)
    {
        int len = source.length();
        String dest = null;
        if(len < maxLength)
            return source;
        boolean truncated = false;
        byte byteSource[] = source.getBytes();
        len = maxLength;
        while(!truncated) 
        {
            dest = new String(byteSource, 0, len);
            if(dest.length() > 0 || len == 0)
                truncated = true;
            else
                len--;
        }
        return dest;
    }

    public static String joinWhere(String oriWhere, String appendedWhere, String joinOperator)
    {
        if(oriWhere == null || oriWhere.length() == 0)
            return appendedWhere;
        else
            return oriWhere + joinOperator + appendedWhere;
    }

    public static String joinWhere(String oriWhere, String appendedWhere, String joinOperator, Object checkCondition)
    {
        if(checkCondition == null)
            return oriWhere;
        else
            return joinWhere(oriWhere, appendedWhere, joinOperator);
    }

}
